import org.dom4j.*;

import java.io.IOException;
import java.util.HashMap;

/**
 * @author ml
 * @create 2017-07-28--17:55
 */
public class WFService {

    private String basePath;
    private String pfuserName;
    private String estateName;
    private String dataBaseIp;
    private String serverIp;
    public WFService(String basePath, String pfuserName, String estateName, String dataBaseIp, String serverIp){
        this.basePath= basePath;
        this.pfuserName=pfuserName;
        this.estateName=estateName;
        this.dataBaseIp=dataBaseIp;
        this.serverIp=serverIp;

    }

    public void changexml() throws Exception{
        Document doc=XmlUtil.parse(basePath+FilePathEnum.WFSERVICE_DBCFG.getValue());
        updateDocByXPATH(doc);

    }

    public void updateDocByXPATH(Document doc) throws DocumentException, IOException {

        XPath datapath=doc.createXPath("//strcon");


        Element dataelement= (Element) datapath.selectSingleNode(doc);

        dataelement.setText("jdbc:oracle:thin:@"+dataBaseIp+":1521:orcl");



        XPath usernamepath=doc.createXPath("//username");


        Element usernameelement= (Element) usernamepath.selectSingleNode(doc);

        usernameelement.setText(pfuserName);


        XPath jndipath=doc.createXPath("//jndiurl");


        Element jndielemet= (Element) jndipath.selectSingleNode(doc);

        jndielemet.setText("tcp://"+serverIp+":61616");

        XPath rmqServerpath=doc.createXPath("//rmqServer");


        Element rmqServerelemet= (Element) rmqServerpath.selectSingleNode(doc);

        rmqServerelemet.setText(serverIp);




        XmlUtil.saveDocument(doc,basePath+FilePathEnum.WFSERVICE_DBCFG.getValue());







    }
}
